#include "include.h"
#include "func.h"
#include "func_idle.h"

#if FUNC_IDLE_EN
extern u8 long_wakeup;
u8 spec_func_mode=0;
u8 key_timeout=0;
u8 long_hold_cnt=0;
extern void test_color(void);
extern void func_ilde_lower_power_check(void);
//#define COLOR_TEST
AT(.text.func.idle.msg)
void func_idle_message(u16 msg)
{
    switch (msg) {

		case KU_BT:
			#ifdef  COLOR_TEST
			func_ilde_reset();
			test_color();
			break;
			#endif
			music_control(MUSIC_MSG_STOP);			
			func_cb.sta =FUNC_BT;
			long_hold_cnt=0;
			break;
		case KL_BT:
			music_control(MUSIC_MSG_STOP);
			sys_cb.bt_mode=1;
			
			func_cb.sta =FUNC_BT;
			long_hold_cnt=0;
			break;
		case KU_MIC:
			spec_func_mode=0;
			long_hold_cnt=0;
			func_ilde_reset();
			func_idle_mic_onoff_ctl();
			break;
		case KLU_MIC:
			long_hold_cnt=0;
			break;
		case KH_MIC:
			long_hold_cnt++;
			printf("hold cnt:%d\n",long_hold_cnt);
			if(long_hold_cnt>=100)
			{
				func_cb.sta =FUNC_EXSPIFLASH_WRITE;
			}			
			//spec_func_mode=1;
			//key_timeout=0;
			break;
			#if 0
		case KL_BT:
			
			long_hold_cnt=0;
			if(spec_func_mode==1)
			{
				spec_func_mode=2;
				key_timeout=0;
				break;
			}
			spec_func_mode=0;
			break;
		case KL_SONG:
			long_hold_cnt=0;
			if(spec_func_mode==2)
			{
				func_cb.sta =FUNC_EXSPIFLASH_WRITE;
				spec_func_mode=0;
				break;
			}
			spec_func_mode=0;
			break;
			#endif
		case KU_POWER:
			if(long_wakeup)
			{
				long_wakeup=0;
				break;
			}
			music_control(MUSIC_MSG_STOP);
			func_cb.sta = FUNC_PWROFF;
			break;
		case KL_POWER:
		case KH_POWER:
			if(long_wakeup)
			{
				break;
			}
			else
			{
				music_control(MUSIC_MSG_STOP);
				func_cb.sta = FUNC_PWROFF;
			}
			break;
		case KLU_POWER:
			long_wakeup=0;
			spec_func_mode=0;
			break;
		case KU_LIGHT:
			spec_func_mode=0;
			func_ilde_reset();
			//test_color();
			func_idle_sfx_ctl();
			break;
		case KL_LIGHT:
			spec_func_mode=0;
			func_ilde_reset();
			func_idle_set_sfx_off();
			break;
		case KU_SONG:
			music_control(MUSIC_MSG_STOP);
			func_cb.sta =FUNC_EXSPIFLASH_MUSIC;
			break;	
		case MSG_SYS_1S:
			func_ilde_lower_power_check();
			#ifndef  COLOR_TEST
			func_ilde_timeout();
			#endif
			if(spec_func_mode)
			{
				key_timeout++;
				if(key_timeout>=3)
				{
					key_timeout=0;
					spec_func_mode=0;
				}
			}
			break;
        default:
            func_message(msg);
            break;
    }
}
#endif // FUNC_IDLE_EN
